home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 15TJPJ8 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.0 KB  |  43 lines

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import com.sun.java.swing.Icon;
  4. import com.sun.java.swing.JComponent;
  5. import com.sun.java.swing.JLabel;
  6. import com.sun.java.swing.JList;
  7. import com.sun.java.swing.ListCellRenderer;
  8. import com.sun.java.swing.UIManager;
  9. import com.sun.java.swing.border.Border;
  10. import com.sun.java.swing.border.EmptyBorder;
  11. import java.awt.Component;
  12. import java.io.Serializable;
  13.  
  14. public class BasicListCellRenderer extends JLabel implements ListCellRenderer, Serializable {
  15.    protected static Border noFocusBorder;
  16.  
  17.    public BasicListCellRenderer() {
  18.       noFocusBorder = new EmptyBorder(1, 1, 1, 1);
  19.       ((JComponent)this).setOpaque(true);
  20.       ((JComponent)this).setBorder(noFocusBorder);
  21.    }
  22.  
  23.    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  24.       if (isSelected) {
  25.          ((Component)this).setBackground(list.getSelectionBackground());
  26.          ((Component)this).setForeground(list.getSelectionForeground());
  27.       } else {
  28.          ((Component)this).setBackground(((Component)list).getBackground());
  29.          ((Component)this).setForeground(((Component)list).getForeground());
  30.       }
  31.  
  32.       if (value instanceof Icon) {
  33.          ((JLabel)this).setIcon((Icon)value);
  34.       } else {
  35.          ((JLabel)this).setText(value == null ? "" : value.toString());
  36.       }
  37.  
  38.       ((JLabel)this).setFont(((Component)list).getFont());
  39.       ((JComponent)this).setBorder(cellHasFocus ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
  40.       return this;
  41.    }
  42. }
  43.